<template>
  <div class="sidebar">
    <div class="sidebar-header">
      <h3 class="sidebar-title">班级信息</h3>
    </div>
    <div class="sidebar-content">
      <div class="class-info-buttons">
        <button class="class-button" v-for="cls in classList" :key="cls.id" @click="selectClass(cls.id)">
          {{ cls.name }}
        </button>
      </div>
    </div>
  </div>
</template>

<script lang="ts">
import { defineComponent, reactive, ref } from 'vue';

export default defineComponent({
  props: {
    classes: {
      type: Array,
      required: true
    }
  },
  emits: ['class-selected'],
  setup(props, { emit }) {
    const classList = reactive(props.classes.map(cls => ({
      id: cls.id,
      name: `3${cls.grade}${cls.classNum}`
    })));

    const selectClass = (classId: number) => {
      emit('class-selected', classId);
    };

    return {
      classList,
      selectClass
    };
  }
});
</script>

<style scoped>
.sidebar {
  width: 160px;
  background-color: #2c3e50;
  color: white;
  height: 100vh;
  position: fixed;
  left: 0;
  top: 0;
  display: flex;
  flex-direction: column;
}

.sidebar-header {
  padding: 20px;
  border-bottom: 1px solid #3a506b;
}

.sidebar-title {
  margin: 0;
  font-size: 18px;
}

.sidebar-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  padding: 20px 0;
}

.class-info-buttons {
  width: 100%;
}

.class-button {
  width: 100%;
  padding: 12px;
  margin-bottom: 10px;
  background-color: #34495e;
  color: white;
  border: 1px solid #3a506b;
  cursor: pointer;
  text-align: center;
  transition: background-color 0.3s;
}

.class-button:hover {
  background-color: #4a6585;
}
</style>
